package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.mapper.DtsGoodsAttributeMapper;
import com.qf.pojo.DtsGoodsAttribute;
import com.qf.service.DtsGoodsAttributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author wanghaotian
 * time:2022/12/21,0021 9:26
 * description:
 */

@Service
public class DtsGoodsAttributeServiceImpl implements DtsGoodsAttributeService {

    @Autowired
    private DtsGoodsAttributeMapper goodsAttributeMapper;

    @Override
    public List<DtsGoodsAttribute> findAttributesByGoodsId(Integer id) {
        LambdaQueryWrapper<DtsGoodsAttribute> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsAttribute::getGoodsId,id);
        wrapper.eq(DtsGoodsAttribute::getDeleted,false);
        List<DtsGoodsAttribute> attributes = goodsAttributeMapper.selectList(wrapper);
        return attributes;
    }

    @Override
    public void deleteByGoodsId(Integer id) {
        LambdaQueryWrapper<DtsGoodsAttribute> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsAttribute::getGoodsId,id);
        goodsAttributeMapper.delete(wrapper);
    }

    @Override
    public void insert(DtsGoodsAttribute attribute) {
        attribute.setDeleted(false);
        attribute.setAddTime(new Date());
        attribute.setUpdateTime(new Date());
        goodsAttributeMapper.insert(attribute);
    }
}
